package org.september.pisces.led.service;

import java.awt.*;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public enum LedColorEnum {

    black(new Color(0, 0, 0)),
    red(new Color(255, 0, 0)),
    orange(new Color(255, 200, 0)),
    yellow(new Color(255, 255, 0)),
    green(new Color(0, 255, 0)),
    blue(new Color(0, 0, 255));


    private Color color;

    LedColorEnum(Color color) {
        this.color = color;
    }

    public static void main(String[] args) {
    	System.out.println(LedColorEnum.getByName("red"));
    }
    public static Color getByName(String name) {
        List<LedColorEnum> list = Arrays.stream(LedColorEnum.values()).filter(num -> num.name().equals(name)).collect(Collectors.toList());
        if (list.isEmpty()) {
            return black.color;
        } else {
            return list.get(0).color;
        }
    }
}
